<?php
/**
 * Created by .
 * User: luogan
 * Date: 2022/1/12
 */

namespace app\admin\controller\v1;


use app\admin\service\AuthMenuService;
use app\interfaces\AdminInterface;
use app\admin\service\AdminService;
use app\admin\validate\AdminValidate;
use hg\apidoc\annotation as Apidoc;

/**
 * @Apidoc\Title("管理员管理")
 * @Apidoc\Group("system")
 * @Apidoc\Sort(1)
 */
class Admin extends Base implements AdminInterface
{

    protected $service;

    protected $validate;

    public function __construct()
    {
       $this->service = new AdminService();
       $this->validate = new AdminValidate();
    }

    public function hello()
    {
        
        echo "RBAC-TP6";
    }

    /**
     * @Apidoc\Title("管理员登录")
     * @Apidoc\Desc("管理员登录")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/admin/login")
     * @Apidoc\Tag("登录")
     * @Apidoc\Param("username", type="string",require=true, desc="用户名",default="admin")
     * @Apidoc\Param("password", type="string",require=true, desc="密码",default="123456")
     * @Apidoc\Returned(ref="app\admin\service\AdminService\login")
     */
    public function login()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->login($data['username'],$data['password']);
        success('登录成功！',$result);
    }

    /**
     * @Apidoc\Title("管理员退出登录")
     * @Apidoc\Desc("管理员退出登录")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/admin/logout")
     * @Apidoc\Tag("退出登录")
     */
    public function logout()
    {
        $result = $this->service->logout();
        success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("管理员权限菜单")
     * @Apidoc\Desc("管理员权限菜单")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/admin/admin_menu")
     * @Apidoc\Tag("退出登录")
     */
    public function adminMenu()
    {
        $adminId = admin_id();
        $result = (new AuthMenuService())->getMenuCache($adminId);
        success('操作成功',$result);
    }
    /**
     * @Apidoc\Title("管理员信息")
     * @Apidoc\Desc("管理员信息")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/admin/admin_info")
     * @Apidoc\Tag("退出登录")
     */
    public function adminInfo()
    {
        $result = admin_info();
        success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("管理员列表")
     * @Apidoc\Desc("管理员列表")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/admin/list")
     * @Apidoc\Tag("管理员")
     * @Apidoc\Param("nickname",type="string",require=false,default="",desc="管理员昵称")
     * @Apidoc\Param("mobile",type="int",require=false,default="",desc="手机号")
     * @Apidoc\Param("email",type="string",require=false,default="",desc="邮箱")
     * @Apidoc\Param("status",type="int",require=false,default="",desc="状态：0 启用 1禁用")
     * @Apidoc\Param(ref="pageParam")
     * @Apidoc\Returned(ref="pageParam")
     * @Apidoc\Returned("data",type="array",ref="app\model\AdminModel\getList",desc="管理员列表")
     */
    public function list()
    {

        $data = $this->checkParam(__FUNCTION__);

        $result = $this->service->getList($data);
        return success('操作成功',$result);
    }


    /**
     * @Apidoc\Title("管理员详情")
     * @Apidoc\Desc("管理员详情")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/admin/info")
     * @Apidoc\Tag("管理员")
     * @Apidoc\Param("id",type="int",require=true,default="1",desc="管理员id")
     * @Apidoc\Returned(ref="app\model\AdminModel\getAdmin")
     */
    public function info()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->getInfo($data['id']);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("管理员新增")
     * @Apidoc\Desc("管理员新增")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/admin/add")
     * @Apidoc\Tag("管理员")
     * @Apidoc\Param("nickname",type="string",require=true,default="",desc="管理员昵称")
     * @Apidoc\Param("username",type="string",require=true,default="",desc="管理员账号")
     * @Apidoc\Param("password",type="string",require=true,default="",desc="管理员密码")
     * @Apidoc\Param("mobile",type="string",require=false,default="",desc="管理员手机号")
     * @Apidoc\Param("head_pic",type="string",require=false,default="",desc="管理员头像")
     * @Apidoc\Param("email",type="string",require=false,default="",desc="管理员邮箱")
     * @Apidoc\Param("sex",type="string",require=false,default="",desc="管理员性别")
     * @Apidoc\Param("role",type="int",require=true,default="",desc="角色")
     * @Apidoc\Param("dept_id",type="string",require=true,default="",desc="部门")
     * @Apidoc\Param("status",type="int",require=false,default="",desc="状态：0 启用 1禁用")
     * @Apidoc\Returned(ref="app\model\AdminModel\getAdmin")
     */
    public function add()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->create($data);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("管理员更新")
     * @Apidoc\Desc("管理员更新")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/admin/edit")
     * @Apidoc\Tag("管理员")
     * @Apidoc\Param("nickname",type="string",require=true,default="",desc="管理员昵称")
     * @Apidoc\Param("username",type="string",require=true,default="",desc="管理员账号")
     * @Apidoc\Param("password",type="string",require=true,default="",desc="管理员密码")
     * @Apidoc\Param("mobile",type="string",require=false,default="",desc="管理员手机号")
     * @Apidoc\Param("head_pic",type="string",require=false,default="",desc="管理员头像")
     * @Apidoc\Param("email",type="string",require=false,default="",desc="管理员邮箱")
     * @Apidoc\Param("sex",type="string",require=false,default="",desc="管理员性别")
     * @Apidoc\Param("role",type="int",require=true,default="",desc="角色")
     * @Apidoc\Param("dept_id",type="string",require=true,default="",desc="部门")
     * @Apidoc\Param("status",type="int",require=false,default="",desc="状态：0 启用 1禁用")
     */
    public function edit()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->update($data);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("管理员删除")
     * @Apidoc\Desc("管理员删除")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/admin/del")
     * @Apidoc\Tag("管理员")
     * @Apidoc\Param("id",type="int",require=true,default="1",desc="管理员id")
     */
    public function del()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->delete($data['id']);
        return success('操作成功',$result);
    }

}
